package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"mxshop_srvs/goods_srv/proto"
)

var brandClient proto.GoodsClient
var conn *grpc.ClientConn

func main() {
	Init()
	//TestBrandList()
	TestCreateBrand()
	//TestUpdateBrand()
	//TestDeleteBrand()
	//TestDeleteBrand()
	//conn.Close()
}

func TestUpdateBrand() {
	banner, err := brandClient.UpdateBrand(context.Background(), &proto.BrandRequest{
		Id:   1113,
		Logo: "https://img2.doubanio.com/view/thing_review/l/public/p6069981.webp",
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(banner)
}

/*
*
创建banner
*/
func TestCreateBrand() {
	banner, err := brandClient.CreateBrand(context.Background(), &proto.BrandRequest{
		Name: "dukeman",
		Logo: "https://img2.doubanio.com/view/thing_review/l/public/p6069972.webp",
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(banner)
}

/*
*
测试获取品牌列表
*/
func TestBrandList() {
	list, err := brandClient.BrandList(context.Background(), &proto.BrandFilterRequest{
		Pages:       1,
		PagePerNums: 20,
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(list.Total)
	for _, brand := range list.Data {
		fmt.Println(brand)
	}
}

/*
*
删除品牌
*/
func TestDeleteBrand() {
	brand, err := brandClient.DeleteBrand(context.Background(), &proto.BrandRequest{
		Id: 1113,
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(brand)
}

// 初始化
func Init() {
	var err error
	conn, err := grpc.Dial("192.168.31.78:50052", grpc.WithInsecure())
	if err != nil {
		panic(err)
	}
	brandClient = proto.NewGoodsClient(conn)
}
